<%--
  Created by IntelliJ IDEA.
  User: 浮犴兮
  Date: 2022/3/24
  Time: 19:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>商品信息页面</title>
    <style>
        table {
            margin: 130px auto 0 auto;
            border: 1px black solid;
            font-size: 24px;
        }

        .tdStyle td {
            padding: 10px;
        }
    </style>
</head>
<body>
<a href="CommodityListController?method=doPost"
   style="color: #F45B4B;font-size: 24px;margin-top:30px;padding-left: 35px">⬅返回主页</a>
<div align="center" style="margin-top: 60px">
    <label style="font-size: 48px">商品${param.method.equals("toAdd")?"增加":"修改"}界面</label>
</div>
<script>
    function checkId() {
        var id = document.getElementById("cId");
        var input_id = id.value;
        if (!/^[0-9]+$/.test(input_id)) {
            alert("输入的条形码不是整数");
            id.style.borderColor = "RED";
        } else {
            id.style.borderColor = "BLACK";
        }
    }

    function checkPrice() {
        var price = document.getElementById("cPrice");
        var input_price = price.value;
        if (!/^[0-9]+\.?[0-9]*$/.test(input_price)) {
            alert("输入的价格不是数字");
            price.style.borderColor = "RED";
        } else {
            price.style.borderColor = "BLACK";
        }
    }
</script>
<div id="main">
    <form action="/editServlet" method="get">
        <input type="hidden" name="method" value="${param.method}">
        <input type="hidden" name="oldcId" value="${requestScope.commodity.cId}">
        <table>
            <tr>
                <td>商品条形码</td>
                <td>商品名称</td>
                <td>商品类型</td>
                <td>商品价格</td>
            </tr>
            <tr>
                <td><input id="cId" type="text" name="cId" size="24px" required style="font-size: 24px"
                           onchange="checkId()"
                           value="${requestScope.commodity.cId}"></td>
                <td><input type="text" name="cName" size="24px" required style="font-size: 24px"
                           value="${requestScope.commodity.cName}"></td>
                <td><select name="cKind" style="font-size: 24px">
                    <option value="食品类">食品类</option>
                    <option value="生活用品">生活用品</option>
                    <option value="服饰类">服饰类</option>
                    <option value="数码类">数码类</option>
                    <option value="工具类">工具类</option>
                </select>
                <td><input id="cPrice" type="text" name="cPrice" size="24px" required style="font-size: 24px"
                           onchange="checkPrice()"
                           value="${requestScope.commodity.cPrice}">
                </td>
            </tr>
        </table>
        <div align="center">
            <button style="margin-top: 15px;font-size: 24px;display:block;">提交</button>
        </div>
    </form>
</div>
</body>
</html>
